//
//  CallRecordCotrollre.m
//  20240823
//
//  Created by 张伟 on 2024/8/24.
//

#import "CallRecordCotroller.h"
#import "RecordCell.h"

@interface CallRecordCotroller ()

@end

@implementation CallRecordCotroller

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configuI];
}

-(void)configuI{

    [self.tableView cellWithNib:RecordCell.class];
    [self addRefreshHeaderAndFooter];
    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(loadData) name:@"canLoadHomeData" object:nil];

}

-(void)loadData {
    NSDictionary * parame = @{
        @"userId":@(UserModel.shared.userId),
        @"page":@(self.page),
        @"pageSize":@(self.pageSize)
    };
    MJWeakSelf
    [NetService requestCallRecordList:parame successHandle:^(NSArray<CallRecordModel *> * _Nonnull array) {
        if (weakSelf.page == 0) {
            [weakSelf.dataSource removeAllObjects];
        }
        [weakSelf.dataSource addObjectsFromArray:array];
        [weakSelf.tableView reloadData];
        [weakSelf endRefresh];
    } fail:^{
        
    }];
}

- (void)refreshAction {
    self.page = 0;
    [self loadData];
}

- (void)loadMoreAction {
    self.page ++;
    [self loadData];
}

@end
